refactored tons. much simpler. input streams should work, but tests not written yet