Removed unnecessary debug echo and removed nested loop