clean up code and fix typos