extracted generate_token to module