added AI, cleaned up JS