Moved checking code into a lambda