clean up and fix bugs