400: Invalid Cursor

Updated the original post with my function.