Fix crash in find dialog and make code less horrible.