Fix for the occasional undefined error with selectedItems

Fix for the occasional: Uncaught TypeError: Cannot read property 'selectedItems' of undefined