Bugfixes for hairfotr's PR