merged sample code from github