Code review fixes: Handling NaN and int overflow