Add bot AI, minor refactor and bug fix.