Cleaned up ai code