Modified main to run in either interactive or non-interactive mode.