Refactor file io into separate module.
Use stream module for parsing input.