factored latest sample code