Added documentation and some fixes