Set class index

Set the class index
Some minor refactory