refactored for DRYness and fixed tag copying