refactoring; optimizations