Added documentation and removed unused variables.