parse_input and general restructuring