Various fixes, part 1
Various fixes, part 2