fixes #195. modified query to always left join on director/instructor/learner-join tables instead based on roles conditions.
code cleanup: free query result after data processing.
Merge pull request #237 from stopfstedt/bug195

fixes #195