Bug fixes. Now tested and working
Added ability control debug mode through a debug parameter