code optimizations and refactorings.