fix crash when unicable matrix is selected, cleanup code