Added comments, some code fixes