Bug fixes for #315