cleaning up a bit of the code, adding comments