ERROR: type " " does not exist at character 149
Nothing shown would explain what you are seeing. Of course, white-space issues are really hard to communicate via email.
As a brute-force suggestion I'd say you want to re-write the function one statement at a time to confirm that, one, you are indeed calling the correct function body, and, two figure out the exact statement that is problematic. I'd do this via copy-paste until the problem statement appears then I'd re-type in the problem statement by hand.
There are probably more efficient ways to do all this but given a lack of experience and a relatively small function I'd spend more effort trying to figure out a better way than just doing it brute force.
David J.