Moved server code in a lib file