Fix crash, tests and measuring