Fix parity calculation
Add constant temp algorithm
Tidy up code