merge (manually edited form of) ceejbot's fix for dependencies.