cleaning up the ai code to be consistent with input