refactoring: cleanup and performance