Moved to before link as code only needs to be executed once

Moved the check to before link as it only needs to be executed once