This is a fatal error
added titlefound function
test titlefound before retrieving data or inserting new records
use local variables in all functions
remove use of tmpfiles and cleanup function