rewrite generate_token method
fix tests