Reorganized sample code