fixed invalid index issue in getElement