some code reordering and some stupid AI