Close reader on exceptional paths

Also tidy up duplicate readLine calls.