Added comments, fixed minor issues