Removed unsafePerformIO, still needs fixing