Fix width calculation and do some cleanup.