removed unnecessary loop and added comments