Various fixes for C-SM, fixes #523