Multiple improvements, adds tests, adds example