added topological ordering

Change-Id: Ifd42a1e6db8bb2aab17866c625dceb3b3e55f850