Changed get_emails function to get_email_count function. Also slightly changed the queries