Fixed a bug in custom loop function

One little oversight has been remedied.