Add comments and reorder the binary search function