This code actually works. Note to self: read the documentation next time