Initial rewrite (untested)