refactor the code to be cleaner