Fixes #428

also add debug mode