fixed bug in query.max