SQL moved to server

Also some refactoring and prep to merge both the files on caesura and
the client.