Fix bugs in the bot code