Bunch of small code cleanup