Hm, no need to check palette < arraysize anymore now that you mask properly.