factored out reading input