Refactor where clause of the main function.