Couldn't get it in a function working, but it works as a script.