Minor tweaks. Added terminal check.