Refactoring to support multiple terminal, refers to #10