Also made some cleanup to build_filter() code by introducing submethods solve_lookup_type() and prepare_lookup_value().