Attempt to restore Tim's changes.
Some fixes