Added comments
Removed unused variables and function. Added documentation.