Deterministic weights option
Small fixes
Partial code cleanup
Partial code cleanup 2
Partial code cleanup 3
Partial code cleanup 4