Refactored token generation into model