Various code, doc and API cleanup/fix/simplification/refactoring