A refactor to make the code more readable and efficient