added checks for exceptional cases