copied material from http://okmij.org/ftp/continuations/ZFS/