Refactor to use less and more maintainable code