Clean up the code to load a dynamic library some more and hopefully make it work on Windows (untested).