refactor some bits, start work on client