Refactor console input/output code