improve current tag detection code