Added double and triple loops