Cleaning and rewriting

doing a lot of commenting and cleaning up