cleaning up code and adding some comments, most likely final commit