adding a check to nil error