Refactored code to include "addItem" function