Minor optimizations/refactoring