fix minor db issue and add $debug