added some bugfixes and improved the demo code a little