replace raw queries in view with query_db() helper