Fix bugs in calculateBarWidth and in _centerBar