Many api tests and a few small bugfixes