misc fixes

misc fixes and code cleanup