fix a bug where assign lastId at incorrect position