updated AI, sorted code a bit