Added AI class, fixed bugs