Bugfixes from local testing