Working code (unless you use old versions of Python)