Refactored input and output