codes refactoring for server side