Lots of tiny changes and bugfixes