fixed buffer pad size and added loops for iterating over image