Refactor quote building code to its own function