Added more documentation. Removed unused variables.