Fix last_pos shifting and add unit test