I don't know why it did not work inside a function, but I managed to resolve the problem by not using a function, and reducing the code in the process as well. Thanks to all who were looking. Best, ~Hans