Major rewrite of the bot