Fixed bug in ensureCorrectDimensions