Improving sample code