Fixed the first and last queries for related managers