use invokeErr from utils
add a few functional utils