updated the helper methods for sorting to prevent sql injection