Couple of small fixes and some code cleanup