speed improvements - binary search instead of linear