updated version with bdds for size 3 and 4