Misc changes

bug fixes, improvements, code cleanup