half working version with attack avoidance