clientmode, servermode, mostly split up and fixed up, needs testing