Added some comments and removed unused variables.