Added checks for database table vs result to avoid adding unneeded results