Add back end logic

implement event logic and change AFI to AFN framework