minor fixes and some code cleanup