rewrite load loop as functions