Adjusted code to centralize DB Query to fit DRY principles.
Modified api3 to conform to new queries.