Bug fixes for #286 and #287