Added bounds checking to X/Y error checking