Added documentation

Added in-line documentation to explain functions and variables