adding some comments, cleaning up code