Externalize common functions and protect inventories