cleaned up code, added commenting