Add median3 implementation