properly capture return status from a function