Misc fixes of rotten code