fix middle element bug