Added logic and test for case without terminal