implemented matrix padding