clean up

cleaned up and commented a bunch of code