subtle bug turns into massive rewrite