Cleaner implementation of expressionDependencies

Rewritten to emphasise the recursive nature of the function.