updates code sample with some minor bug fixes