Fix resolving dependency algorithm