sorting code patterned on scikits learn but not used as it is slower then go's sort for now