spruced up some code as well as fixed a few bugs that were giving me nan's in ai and at