Make the buffered reader more robust
Simplify function