moved main read function to try...finally block