complete refactoring and cleanup