rewrite extendP, extendN