Refactor setup into reusable function