This is how it could look! Perhaps you can build in a safety condition (if palette ID > 7, then palette ID = 0).