Added input_gen(), various other improvments