Corrected check for boundary  condition