Fix for Cannot read property 'id' of undefined