Added file pointer check