Overhaul I/O, fix control flow, add devices