Add get_shell method

Also reorganize code to make it slightly easier to test