Isolated server logic into its own module. Also cleaned some dead & commented code