Much more robust check for dependencies. Fixes #4