Fix errors thrown during commands

Also remove the debug code