complete documentation, fix type errors discovered during doctesting.