Added documentation + minor code fixes