fixes #914
avoid global variables
mw code debug