make everything works with MySQL 5.5

make everything works with MySQL 5.5
patching median function (you may decide to keep it old way)