Only do the layer sorting for xor and inv gates

Effectively minimizes the number of ands
Renamed class and fixed output