Refactor sm module. Fix feature negotiation ordering