modularized the server code --KW