reimplement streams and change API