Server refactor

Not quite finished, but should be good enough that we can start building features off of it.