Most functions working except sorting