Large refactoring and inital support for tracking