Moved scope exit down as this fails to compile on windows.

Moved scope exit down as this fails to compile on windows.