Reimplements --debug

KIS kind of patch. It also fixes the debug support.