Move prepare logic to a separate method.