removed unused variables, and added some comments