fixed some AI bugs and some cleanup