Fix string comparisons (put space around [] chars). Rearrange order of command execution.