Refactoring to handle undefined datastreams