Tidied up the scripting engine code.

Made the library buildable in VS2012, and hopefully still 2013. 2010 untested.

General code cleanup.