Added a debug mode and slightly improved script and non-script modes.