fix typos
more cleanup, separation of functionality