Added check for dimensions sanity