thanks @Ron64! finally fixed the leak
get rid of statics and test mode
clean up and defines