Various bugfixes

Thanks PeridexisErrant for noting some bugs