Some improvement to palette code