Added checking against zero, correct file opening.