Lots of small fixes to make everything behave like it should.