fixes #1 and fixes #2. also identifies issue with DELETE_ORPHANS sql command