Adding dimension check to prevent breaking execution in all() in case of different matrix dimensions