Fixed undefined error when there is no element in the model