FIX: generalised code for any length of s,x,y,h