Move pkg to package.sh, fix various bugs.