Added API and a few code cleanups