Updated incorrect use of ksort(), also fixed unittests