Various minor bug fixes and improvements
