Tidied logic in embedInStream