[#1813] Regression: fix unbinding of collections and arrays from Groovy templates

The important part are the unbindCollection() and unbindArray() methods.
Other stuff just improves code readability while searching for the cause of the bug.

Regression was introduced with the fix of #1727.