rewrite server reading logic