Factored out token generation