Fleshed out API. Fixed bugs.