Calculate F and W refactored. Code inline.