Roughly complete documentation, small fixes in API and tests