Reworked the colouring function