Some cleanup, along with some work on using the correct calling convention for script hooks.