code cleanups, api improvements