improved example and fixed a few bugs