Cleanup API.
Also cleaned code up a bit.