Mike refactor table sort

Please ignore this file, this is a copy paste and hopefully a temporary fix