refactor database script; add communication connectivity to database