Cleaning up code, adding comments.