added file pointer check