More fixes for the previous rewrite