refactor: simplify extend/unextend functions