Could you use some more descriptive variable names? ``p`` is so widely used that it may be OK, but ``Tk`` and ``tm`` are not. Same comment for the internal variables, they're almost all one-letter which isn't readable.