complete rewrite with working client