Added comments and cleaned some code.