Rewrite with more object orient approach. Now includes AI