Add the then function with non-void return type. Update tests.