Implemented pseudocode for addItem