Sorting functions added. Code is working now