Added documentation to most functions