clean up

clean up code and add some general comments