begin to factor out common file descriptor usage