Re-factored some code handling return values and fails/errors during tool execution. Reviewed-by: sla, kevinw