Add adaptive bin size function