working version with fast binary search (database free)