Implemented I/O multiplexing. Removed unused code. Minor syntax bugfixing