Fixed IOStream closed on loop, minor fixes