improve ExpandTree/Line recursion

- fix end condition in case of unknown/bad command
- added/rearranged debug messages