modifed sample code