adding some tree and stack related functions