code cleanup and bug fixes
cleanup