Server refactor

@bmizerany @unihorn