Added check for matching dimensions