Improve padding calculation