Refactoring to reduce code size