Optimizations & refactoring