a bit of restructuring and added best_fit utility