Refactored the scripting interface greatly.