nil check prevents unexpected TypeErrors