An undefined index error and a small improvement