fixed bug in C impl for not using sorted data