update server code

rewrote my original contribution to working, [hopefully] more pythonic
code.