Better error handling
Fixed palette indexing bug