used res instead of global variable data fixes #4