Not your doing, but this so called 'check' function is modifying the input cube in place.