added a test/example and fixed some bugs