Fixed weighted median algorithm, added a few tests