fixes some bugs in the sample code