fixed the join statements. need to get it to be reusable