Changed the operation of --safe as noted in the help section.
Added several levels of error detection to prevent orphaned entries in the DB.