fixes to tag patching; some code clarity improvements