Fix inconsistency in selected_token_index

Fixes bug #604