bug fixes and small ai improvement