modified the logic after fieldtest