Refactor to make the code cleaner