fixxed global var to local! now doc is defined ;)