Misc fixes and API improvements.