finalized sample code