change .parentNode on .appendChild(); small refactoring