added comments and removed unnecessary code