add emfile error handling and other