several bugfixes and cleanups
#for should end with #end for