source and target trees functioning (ugly javascript though)