refactor: check required global variables only once

Closes #24