Improve file and stdin support