Changed way of taking padding into account