Some code cleanup and a command tree bug fix.