refractoring tornado code