added func to find the smallest bitDepth that can contain a distance and a few minor tweaks