revised the sample code