Fix a few annoying bugs