refactoring and cleanup.