Moved packagedir var down into proper scope