Fix some bugs with the palette, syntax cleanup, add comments.