Bug fixes for table sorting