Move output to methods and clean up code