API overhaul, and a few bugfixes