add tests for edge case and refactored code regarding the handling of NaN