fixed file handler function