System.in replaced with InputStream for ease of unit testing