move logics to class PYEngine