added children iteration utility function and refactored some places to use it