fix bug that causes ClassCastException.