refactored criteria checking algorithm