Major API fixes and doc improvements