Refactor the code to allow for a better output