improve file handler and export