Fix warning. Extract some code to help write sample