Fix bug with NaN, add initial test coverage