Add a test case. Reformat production code. Fix bug of reading input and error streams.