Lots of debugging and works in tests