added more comments and removed unnecessary variable