sorting out undefined variable