changed to nearest matrix