fixed bug returning last result instead of first