Moved output setup into library function