changed loop in nested loop and removed magical number