Refactor this check to a method