refactoring to separate common server code