added more tests and fixed medie algorith<