this is turning out to be quite the rewrite