Fixing the Undefined index error