a very buggy stream implementation