Fix undefined index warning and remove a commendedout code