more refactoring and cleanup

read commits for summary if you want.