Added tree and polygon generation. Fixed a bug in the merge function.