fix order of masking key initialization and use
update scratch examples
fix missing return value
fix unused variable