Fixed a couple var scoping issues, plus workaround for packages in subfolder.