Several more bug fixes