added coordinate checking function