cleaning up code, adding comments