fix stream not being closed in module constructor