Fix tests, fix a memory leak, improve packaging a bit