remove unused imports; add output redirection detect; add return code; simplify and refine
fix bad variable name
Merge pull request #2 from oxnz/master

remove unused imports; add output redirection detect; add return code; simplify and refine