Compilable, still need testing + bilinear interpolation