Refactored/cleaned trace.py