Not perfectly sure, but perhaps this would be cleaner with a "case" statement style check?