added comments,corrected code