Added a OnceOnly functor to simplify some code, additional useage of foreach.