Added caching and sorting ability for relations