Various bugfixes
Minor improvements