Added documentation and some minor fixes