Fixes has_many_through function. Final version.