refactor to share more code between cli and gui
initial check-in