Fixed the min/max queries