Isolate unsafePerformIO calls into separate module

This reduces the scope where optimizations must be disabled.