added sort(function)
created switch function