Bugfixes and API optimization