GRIM: Make the lights sorting stable. Fix #678