repair dbl implementation (second for loop)
moved commonly useful things to common dir