updated database code

working version of database script

-edward