added tests, refactored, check to filter out NaN results