Add documentation, reimplement query.max and query.min