improve sample code