Fixing a few important bugs