Fix function retrn on error cases
wip