Added extra error checking to debug why this isn't working.