added general explanation and sample code