adjusted the binstartend function