Input file is no longer read three times, and some other changes.