modularized the bd function