fix index out of bound error for gui