Many fixes, palette handling reworked