This is copy from sample code.