correcting initialisation of veriables in for loop
removing hardcoded params and changing function name
dynamically handling mapping of pixels in low end slices