Added various checks for corner conditions