cleaned up server code, moded into client