Fix bug in previous and new position comparison logic