Rewrote code to use afnwith