Bunch of code tweaks. Should not change any behaviour.