refactoring: moving some pyserver logic to separate files