Changed from checking for null to checking for undefined