added some code to dimension checking