added debug code and renamed var