Avoiding race condition from #29, closing streams properly and not closing stream we are trying to open. Closes #52