purify functions
generated functions now have basic docstrings
calculate mask from cast to cast