Refactored into main and iohandler