A bunch of changes to try and fix bugs.