* add if exists to database creation
* fixed issue with creation of function
* clean up.