A large number of fixes for Ethan's code.