Fixes tests and adapts code