Remove spaghetti code