Bugfixes and improvements
Minor code improvements and fixes