Undefined index bug fix