Palette handling fixes

Fixes #513. 

[] should check on #434 and add specific test.