That is entirely valid except for a small logical error that the else is only applying to the second if() statement there. You return the function in them anyway, so it doesn't produce a real difference, but the second if() statement should be else if() if you are going to do things that way.