Prevent infinite loop when input file is empty

for issue #22