Server side code almost done.

Only minor tweaks will be needed.