start of sorting devices(will finish/fix later)