Fix various bugs/problems for packaging