Extract condition checking to a function.