Added comments, shortened redundant code