added return functionality in topologicalsort