Change package install sequence

The original sequence of installing the package before checking the namespace causes needless overhead. Now, we first check the namespace and throw an exception early if it is missing.