improve "SmartOpenTag" function