added binary search and initialization function