Cleaned up and simplified code, made tracking functionality a module