Various general bug fixes