Various minor bug fixes