bugfix and fixing tests