Fix undefined index notice bug
fixed conflicts in pull request
Make sure the attribute key exists before setting it