refactor and fixing

refactor the code.
add dns cache