extract output into a function