refactor to support code reuse

This is the precursor to a console based client, reusing as much code as possible from the browser client