Add debug logging and fix re-printing of the typed commands