Merge changes from Anders

With tweaks