cleaning up code and adding comments