cleaned up code and commented