added comments and removed redundant code