Slightly refactor form search code