better source_gen and non-mps code scopes (though not precise)
remove redundant type casts