fixed the bug when the last position was not returned