clean up the code and fix issues