Use has_key? rather than accessing the value
Simplify nested conditional
Delete rather than assign nil
Assign this inline