removed global vars, this commit is buggy! I will fix it ;)