Optimize the sample code