Refactor code

chanded getEvents and getEvents query to include join, thereby
eliminating multiple queries and complicated operations.