refactor a lot for Web
finish refactor server