changed way of catching EOF from -1 to throw