Added terminate function