Refactoring and compilation optimizations