bug: incorect using max_id insted of min_id