Working AI(with minor bugs...)