Optimizations and readability refactorings