Introduce VariableDependency and use it to simplify related code