Added more logic to handle tagged/untagged