Refactored badly written code in tracker