Fixes #804 - Make sure that streams are closed prior to attempting file move operations to prevent ownership problems on Windows