Refactor code for cleanliness