Moved most server shared code to here