tested and fixed example code