The code in the IF condition might be a good candidate for a function that returns bool.