Sorting

Created sorting and heuristic functions