I'm not sure the snippet you posted is correct though. The code above looks for the smallest possible __unused__ color, while your looks for the smallest used color