Fixing a bunch of bugs