complete refactor of client logic, still needs some edge case/error handling and additional tests, but there is a fair amount of testing now