Added guard when calculated colour index is negative