reworked appendNodes method