Lots of little changes and bugfixes