Recoded DOTZ function. Most of the function names were taken directly from the python code in an effort to prevent confusion.