Refactor transformation code for better maintainability