Implemented I/O expander for keyboard input. Also fixed some bad memory management.