Refactor code to make it more maintainable