updated and added final sample code