almost functional but currently not working -- lazy io?