Refactord the criteria handling.