Add debugging info for when NaN-related tests fail and refactor a bit