add functions in utils.h for tree construction