Added matrix stacking function