Fix for cases where res is undefined at the end of the cutoff