bug fix related to memory leak and max out file descriptor