Added comments and prettyafied some code