You're welcome to improve it (or leave it how you had it, though I think if the logic is switched a bit it'll be simpler) - the key is to keep it out of the code doing the work :)