clean and refactor code