Various code enhancements.
Fix g1s threshold synthesis bug: take top-level negations into account.