reorganise, improve token detection