Copied fix for shifting problem to tee.py