added example code and tidied it up some