cleanup and refactor the code.