Cleaned up code. Insert and remove Z tags code was abstracted into
methods. Not sure how to fix line break problem.