Fixing a number of bugs