improve dimension checking