Implemented aggregate logic for medians