misc fixes and code cleanup