Some fixes in createTree function