Added stdin handling and a test for it.