Added documentation and  various fixes