Misc fixes

Apologies for sending you broken code earlier. Fixed.