Fixed NIL bug in isValid() method, reported by @ocubom in PR #11