Improved variable reference resolving algorythm