Refactor parsing of criteria