cleaning up code and adding additional comments