bugfix and some tests