get rid of unnecessary loops