Added topological sort and corrected isAcyclical