Refactored w4.1 median