Various fixes to #299