Improved sample code