Added comments and simplified some things.