Single-line while cases with multiple commands now handled.
Fixed variable substitution in while/for loops, modified indenting and modularised it too.