more refactoring and some cleanup
more refactoring