Refactor code to make it simple