Fix various issues with packaging and add tests for them