improved streaming support, removed unused code, added tests