cleaning up a bit of code, adding comments