refactor code for clietn server