Refactored JW code