Added example and fixed few bugs