Moved tracheal tube removal to a function

Also reduced memory usage by releasing memory in this mini-pipeline.