Optimizations and palette support.
Merge pull request #1 from akaseva/master

Optimizations and palette support.