Used Chan instead of IORef for key callback interface, other changes