fix potential nan results