Fixing a variety of bugs and inconsistencies