Fixed file descriptor issues