finished but AI and refactor