changed handling, minor bugfixes, added tests