pkgs: refs #2112 refactoring code