Rewrite memorystream to be a proper util