Ensure BED combining and temporary directories happen within safe transactions to avoid race conditions. Thanks to @lpantano