complete createCodeTree function