Added some customisation options.
Added saner debug handling and more debug info.
Very minor optimisations.