Used a global hash to store used colours to avoid recalculating each time