fixes wrong test results
fixes memory leaks