changed the schema, used single query for maximum