Added occurrence sort function