Split off input_context code into separate file