Restructure the ticket construction code