refactoring, optimizations