Refactored stdout side effects from bin to lib