Various changes in code to fix bugs.