adds logic to prevent one of the 'length of undefined' errors