probably fixed #32 and fixed #32 by not using local variables and some other tweaks (see also #28)