improved sample code further, also added c# sample code