Modularized the bot a bit and added safety checks.