Refactored output code