Fix input width calculation and avoid unnecesary digest