Refactored code to use xtypes, itemIds, and function pointers