Fixed a bug in finding median