working AI, does not detect end