WIP to support dynamic palette (doesn't work yet)