optimizations & refactoring