Sorting now works

Changed $elem to $($elem) in a few places