Hello, and thanks for the feedback.
The code is mostly C&P, so I didn't know if I should reformat it. I'll try to merge the two functions and fix the indentation in the process. Just wasn't sure if I should touch the working function or rather make a new one for my purposes. I'll resend the patch when I'm finished and have done the required tests.
Fabian