This reverts commits 044a1048ca and 1be456ae9d, adapting the code to changes that happened after it.
044a1048ca
1be456ae9d