holy comments batman! added commenting to clarify algorithms and clean up code