API cleanup and bug fixes.