more robust code for creating tags