constants defined outside loop
bug fixed