Added comments and removed redundant code