Finished writing code for non-interactive mode